import { request } from '@/utils/request';
import { RequestEnum } from '@/enums/httpEnum';

export const categoryApi = {
  categoryList: '/category/list',
  categoryDetail: '/category/detail',
  categoryAdd: '/category/add',
  categoryUpdate: '/category/update',
  categoryDelete: '/category/delete',
  listJson: '/category/listJsonByType',
} as const;

export const createCategory = (data: API.CreateCategoryParams) => {
  return request({
    url: categoryApi.categoryAdd,
    method: RequestEnum.POST,
    data,
  });
};

export const updateCategory = (data: API.UpdateCategoryParams) => {
  return request({
    url: categoryApi.categoryUpdate,
    method: RequestEnum.PUT,
    data,
  });
};

export const deleteCategory = (params: { id: number }) => {
  return request({
    url: categoryApi.categoryDelete,
    method: RequestEnum.DELETE,
    params,
  });
};

export const categoryJsonByType = (params: { type: number }) => {
  return request({
    url: categoryApi.listJson,
    method: RequestEnum.GET,
    params,
  });
};
